//using System.Collections;
//using System.Collections.Generic;
//using UnityEditor.Experimental.GraphView;
//using UnityEngine;

//public class Path2D : MonoBehaviour
//{

//    public Transform seeker, target;
//    Grid2D grid;
//    Node2D seekerNode, targetNode;
//    public GameObject GridOwner;


//    List<Vector3> mDots = new List<Vector3>();
//    void Start()
//    {
//        //Instantiate grid
//        grid = GridOwner.GetComponent<Grid2D>();
//    }
//    void Update()
//    {
//        mDots.Clear();
//        var nodes = FindPath(seeker.position, target.position);
//        for (int i = 0; i < nodes.Count; i++)
//        {
//            var node = nodes[i];
//            mDots.Add(node.ToV2());
//        }
//        if (mDots != null && mDots.Count >= 2)
//        {
//            for (int i = 1; i < mDots.Count; i++)
//            {
//                Debug.DrawLine(mDots[i - 1], mDots[i], Color.green);
//            }
//            Debug.DrawLine(mDots[mDots.Count - 1], mDots[0], Color.green);
//        }
//    }


//    public List<Node2D> FindPath(Vector3 startPos, Vector3 targetPos)
//    {
//        //get player and target position in grid coords
//        seekerNode = grid.NodeFromWorldPoint(startPos);
//        targetNode = grid.NodeFromWorldPoint(targetPos);

//        List<Node2D> openSet = new List<Node2D>();
//        HashSet<Node2D> closedSet = new HashSet<Node2D>();
//        openSet.Add(seekerNode);

//        //calculates path for pathfinding
//        while (openSet.Count > 0)
//        {

//            //iterates through openSet and finds lowest FCost
//            Node2D node = openSet[0];
//            for (int i = 1; i < openSet.Count; i++)
//            {
//                if (openSet[i].FCost <= node.FCost)
//                {
//                    if (openSet[i].hCost < node.hCost)
//                        node = openSet[i];
//                }
//            }

//            openSet.Remove(node);
//            closedSet.Add(node);

//            //If target found, retrace path
//            if (node == targetNode)
//            {
//                return RetracePath(seekerNode, targetNode);
//            }

//            //adds neighbor nodes to openSet
//            foreach (Node2D neighbour in grid.GetNeighbors(node))
//            {
//                if (neighbour.obstacle || closedSet.Contains(neighbour))
//                {
//                    continue;
//                }

//                int newCostToNeighbour = node.gCost + GetDistance(node, neighbour);
//                if (newCostToNeighbour < neighbour.gCost || !openSet.Contains(neighbour))
//                {
//                    neighbour.gCost = newCostToNeighbour;
//                    neighbour.hCost = GetDistance(neighbour, targetNode);
//                    neighbour.parent = node;

//                    if (!openSet.Contains(neighbour))
//                        openSet.Add(neighbour);
//                }
//            }
//        }


//        return openSet;
//    }

//    //reverses calculated path so first node is closest to seeker
//    List<Node2D> RetracePath(Node2D startNode, Node2D endNode)
//    {
//        List<Node2D> path = new List<Node2D>();
//        Node2D currentNode = endNode;

//        while (currentNode != startNode)
//        {
//            path.Add(currentNode);
//            currentNode = currentNode.parent;
//        }
//        path.Reverse();

//        grid.path = path;
//        return path;
//    }

//    //gets distance between 2 nodes for calculating cost
//    int GetDistance(Node2D nodeA, Node2D nodeB)
//    {
//        int dstX = Mathf.Abs(nodeA.GridX - nodeB.GridX);
//        int dstY = Mathf.Abs(nodeA.GridY - nodeB.GridY);

//        if (dstX > dstY)
//            return 14 * dstY + 10 * (dstX - dstY);
//        return 14 * dstX + 10 * (dstY - dstX);
//    }
//}